package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.CartoonTextsBean;
import com.fancy.learncenter.common.JumpIntentKey;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;

import java.util.List;

/**
 * Created by shiweiwei on 2017/12/13.
 */

public class EnglishSentenceAdapter extends CommonRecycleViewAdapter<CartoonTextsBean> {

    public void setListener(ClickListener listener) {
        this.listener = listener;
    }

    ClickListener listener;
    JumpIntentKey.QUESTION_ENTER_TYPE type;

    public EnglishSentenceAdapter(Context mContext, List<CartoonTextsBean> itemDatas, JumpIntentKey.QUESTION_ENTER_TYPE type) {
        super(mContext, R.layout.fill_blank_sentence_item, itemDatas);
        this.type = type;
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final CartoonTextsBean item, final int position) {
        TextView sentenceText = customViewHold.getView(R.id.sentence_text);

        switch (type){
            case DO_IT_AGAIN:
            case DO_WORK:
            case CONTINUE_WORK:
            case ERROR_KINDS:
                customViewHold.getRoorView().setEnabled(true);
                break;
            case WORK_REPORT:
                customViewHold.getRoorView().setEnabled(false);
                break;
            case NO_CLICK:
                customViewHold.getRoorView().setEnabled(false);
                break;
        }

        if (item.getStatus() == null){
            item.setStatus(JumpIntentKey.OPTION_STATUS.STATUS_DEFAULT);
        }

        if (item.isHidden() == 0) {

            switch (item.getStatus()){
                case STATUS_DEFAULT:
                    customViewHold.getRoorView().setBackgroundColor(mContext.getResources().getColor(R.color.cartoon_text_slected));
                    break;
                case STATUS_CHOOSE:
                    customViewHold.getRoorView().setBackgroundColor(mContext.getResources().getColor(R.color.cartoon_text_slected));
                    break;
                case STATUS_RIGHT:
                    customViewHold.getRoorView().setBackgroundResource(R.mipmap.cartoon_word_long_right);
                    break;
                case STATUS_WRONG:
                    customViewHold.getRoorView().setBackgroundResource(R.mipmap.cartoon_word_long_wrong);
                    break;
            }

            sentenceText.setText(item.getValue());

        }else {

            sentenceText.setText("");
            customViewHold.getRoorView().setBackgroundColor(mContext.getResources().getColor(R.color.transparent));
        }


        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (listener != null){
                    listener.click(item,position);
                }
            }
        });
    }

    public interface ClickListener {
        void click(CartoonTextsBean value, int position);
    }
}
